import { createRouter, createWebHashHistory } from "vue-router";
import Home from "../views/Home.vue";


const routes = [
    {
        path: '/',
        redirect: '/dashboard'
    }, {
        path: "/",
        name: "Home",
        component: Home,
        children: [
            {
                path: "/dashboard",
                name: "dashboard",
                meta: {
                    title: '系统首页'
                },
                component: () => import( /* webpackChunkName: "dashboard" */ "../views/Dashboard.vue")
            },
            {
                path: "/TicketTaskList",
                name: "TicketTaskList",
                meta: {
                    title: '工单任务列表'
                },
                component: () => import( /* webpackChunkName: "dashboard" */ "../views/TicketTask/TicketTaskList.vue")
            }, {
                path: "/TicketTaskAdd",
                name: "TicketTaskAdd",
                meta: {
                    title: '工单任务新增'
                },
                component: () => import( /* webpackChunkName: "dashboard" */ "../views/TicketTask/TicketTaskAdd.vue")
            },
            {
                path: "/TicketTaskDetails",
                name: "TicketTaskDetails",
                meta: {
                    title: '工单任务详情'
                },
                component: () => import( /* webpackChunkName: "dashboard" */ "../views/TicketTask/TicketTaskDetails.vue")
            },
            {
                path: "/ProductList",
                name: "ProductList",
                meta: {
                    title: '产品列表'
                },
                component: () => import("../views/product/ProductList.vue")
            },
            {
                path: "/ProductInsert",
                name: "ProductInsert",
                meta: {
                    title: '新增产品'
                },
                component: () => import("../views/product/ProductInsert.vue")
            },
            {
                path: "/ProductSelect",
                name: "ProductSelect",
                meta: {
                    title: '产品详情'
                },
                component: () => import("../views/product/ProductSelect.vue")
            },
            {
                path: "/ShowMaterial",
                name: "ShowMaterial",
                meta: {
                    title: '物料管理'
                },
                component: () => import( /* webpackChunkName: "dashboard" */ "../views/Material/ShowMaterial.vue")
            }, {
                path: "/AddMaterial",
                name: "AddMaterial",
                meta: {
                    title: '物料新增'
                },
                component: () => import( /* webpackChunkName: "dashboard" */ "../views/Material/AddMaterial.vue")
            },
            {
                path: "/DetailsMaterial",
                name: "DetailsMaterial",
                meta: {
                    title: '物料详情'
                },
                component: () => import ( /* webpackChunkName: "dashboard" */ "../views/Material/DetailsMaterial.vue")
            },
                //生产计划
                {
                    path: "/ShowProductionPlanning",
                    name: "ShowProductionPlanning",
                    meta: {
                        title: '生产计划列表'
                    },
                    component: () => import ( /* webpackChunkName: "dashboard" */ "../views/ProductionPlanning/ShowProductionPlanning.vue")
                },  {
                    path: "/AddProductionPlanning",
                    name: "AddProductionPlanning",
                    meta: {
                        title: '生产计划新增'
                    },
                    component: () => import ( /* webpackChunkName: "dashboard" */ "../views/ProductionPlanning/AddProductionPlanning.vue")
                },
                {
                    path: "/DetailsProductionPlanning",
                    name: "DetailsProductionPlanning",
                    meta: {
                        title: '生产计划新增'
                    },
                    component: () => import ( /* webpackChunkName: "dashboard" */ "../views/ProductionPlanning/DetailsProductionPlanning.vue")
                },
             {
                path: "/table",
                name: "basetable",
                meta: {
                    title: '表格'
                },
                component: () => import( /* webpackChunkName: "table" */ "../views/BaseTable.vue")
            }, {
                path: "/charts",
                name: "basecharts",
                meta: {
                    title: '图表'
                },
                component: () => import( /* webpackChunkName: "charts" */ "../views/BaseCharts.vue")
            }, {
                path: "/form",
                name: "baseform",
                meta: {
                    title: '表单'
                },
                component: () => import( /* webpackChunkName: "form" */ "../views/BaseForm.vue")
            }, {
                path: "/tabs",
                name: "tabs",
                meta: {
                    title: 'tab标签'
                },
                component: () => import( /* webpackChunkName: "tabs" */ "../views/Tabs.vue")
            }, {
                path: "/donate",
                name: "donate",
                meta: {
                    title: '鼓励作者'
                },
                component: () => import( /* webpackChunkName: "donate" */ "../views/Donate.vue")
            }, {
                path: "/permission",
                name: "permission",
                meta: {
                    title: '权限管理',
                    permission: true
                },
                component: () => import( /* webpackChunkName: "permission" */ "../views/Permission.vue")
            }, {
                path: "/i18n",
                name: "i18n",
                meta: {
                    title: '国际化语言'
                },
                component: () => import( /* webpackChunkName: "i18n" */ "../views/I18n.vue")
            }, {
                path: "/upload",
                name: "upload",
                meta: {
                    title: '上传插件'
                },
                component: () => import( /* webpackChunkName: "upload" */ "../views/Upload.vue")
            }, {
                path: "/icon",
                name: "icon",
                meta: {
                    title: '自定义图标'
                },
                component: () => import( /* webpackChunkName: "icon" */ "../views/Icon.vue")
            }, {
                path: '/404',
                name: '404',
                meta: {
                    title: '找不到页面'
                },
                component: () => import(/* webpackChunkName: "404" */ '../views/404.vue')
            }, {
                path: '/403',
                name: '403',
                meta: {
                    title: '没有权限'
                },
                component: () => import(/* webpackChunkName: "403" */ '../views/403.vue')
            }, {
                path: '/user',
                name: 'user',
                meta: {
                    title: '个人中心'
                },
                component: () => import(/* webpackChunkName: "user" */ '../views/User.vue')
            }, {
                path: '/editor',
                name: 'editor',
                meta: {
                    title: '富文本编辑器'
                },
                component: () => import(/* webpackChunkName: "editor" */ '../views/Editor.vue')
            }, {
                path: "/WorkOrder",
                name: "WorkOrder",
                meta: {
                    title: '编号规则'
                },
                component: () => import ( /* webpackChunkName: "login" */ "../views/WorkOrder/WorkOrder.vue")
            }, {
                path: "/ProductionWork",
                name: "ProductionWork",
                meta: {
                    title: '生产工单'
                },
                component: () => import ( /* webpackChunkName: "login" */ "../views/WorkOrder/ProductionWork.vue")
            }, {
                path: "/SchedulingWork",
                name: "SchedulingWork",
                meta: {
                    title: '生产排产'
                },
                component: () => import ( /* webpackChunkName: "login" */ "../views/WorkOrder/SchedulingWork.vue")
            }
            , {
                path: "/ProcessShow",
                name: "ProcessShow",
                meta: {
                    title: '工序路线'
                },
                component: () => import("../views/Process/ProcessShow.vue")
            }
            , {
                path: "/ProcessAdd",
                name: "ProcessAdd",
                meta: {
                    title: '工序路线添加'
                },
                component: () => import("../views/Process/ProcessAdd.vue")
            }
            , {
                path: "/CrafProcessShow",
                name: "CrafProcessShow",
                meta: {
                    title: '工艺路线'
                },
                component: () => import("../views/CrafProcess/CrafProcessShow.vue")
            }
            , {
                path: "/CrafProcessAdd",
                name: "CrafProcessAdd",
                meta: {
                    title: '工艺路线添加'
                },
                component: () => import("../views/CrafProcess/CrafProcessAdd.vue")
            },
            //BOM
            {
                path: "/BOMShow",
                name: "BOMShow",
                meta: {
                    title: 'BOM列表',
                    module: '4',
                },
                component: () => import("../views/BOM/BOMShow.vue")
            },
            {
                path: "/BOMAdd",
                name: "BOMAdd",
                meta: {
                    title: 'BOM添加'
                },
                component: () => import("../views/BOM/BOMAdd.vue")
            },
            {
                path: "/BOMDetails",
                name: "BOMDetails",
                meta: {
                    title: 'BOM详情'
                },
                component: () => import("../views/BOM/BOMDetails.vue")
            },
            {
                path: "/MaterialRequiseShow",
                name: "MaterialRequiseShow",
                meta: {
                    title: '生产领料显示',
                    module: '4',
                },
                component: () => import("../views/Production/MaterialRequiseShow.vue")
            },
            {
                path: "/InFormList",
                name: "InFormList",
                meta: {
                    title: '通知公告',
                    module: '4',
                },
                component: () => import("../views/Inform/InFormList.vue")
            },
            {
                path: "/InFormAdd",
                name: "InFormAdd",
                meta: {
                    title: '通知公告添加',
                    module: '4',
                },
                component: () => import("../views/Inform/InFormAdd.vue")
            },
            {
                path: "/AnnouncementShow",
                name: "AnnouncementShow",
                meta: {
                    title: '通知列表',
                    module: '4',
                },
                component: () => import("../views/Announcement/AnnouncementShow.vue")
            },
            {
                path: "/AnnouncementFind",
                name: "AnnouncementFind",
                meta: {
                    title: '通知内容',
                    module: '4',
                },
                component: () => import("../views/Announcement/AnnouncementFind.vue")
            }
            

        ]
    }, {
        path: "/login",
        name: "Login",
        meta: {
            title: '登录'
        },
        component: () => import( /* webpackChunkName: "login" */ "../views/Login.vue")
    },


];

const router = createRouter({
    history: createWebHashHistory(),
    routes
});

router.beforeEach((to, from, next) => {
    document.title = `${to.meta.title} | vue-manage-system`;
    const role = localStorage.getItem('ms_username');
    if (!role && to.path !== '/login') {
        next('/login');
    } else if (to.meta.permission) {
        // 如果是管理员权限则可进入，这里只是简单的模拟管理员权限而已
        role === 'admin'
            ? next()
            : next('/403');
    } else {
        next();
    }
});

export default router;